#include <string.h>
#include <stdint.h>
#include <openssl/evp.h>

int main(int argc, const char *argv[])
{
	EVP_ENCODE_CTX ectx, dctx;
	uint8_t in[500], out[800], d[500];
	int i, inl, outl, total, ret;

	EVP_EncodeInit(&ectx);
	for (i = 0; i < 500; i++)
		in[i] = i;

	total = 0;
	inl = 500;
	EVP_EncodeUpdate(&ectx, out, &outl, in, inl);
	total += outl;
	EVP_EncodeFinal(&ectx, out + total, &outl);
	total += outl;
	printf("%s\ntotal len %d\n", out, total);



	EVP_DecodeInit(&dctx);
	inl = total;
	total = 0;
	ret = EVP_DecodeUpdate(&dctx, d, &outl, out, inl);
	if (ret < 0) {
		printf("Decode update failed\n");
		return 0;
	}
	total += outl;

	ret = EVP_DecodeFinal(&dctx, d + total, &outl);
	total += outl;

	printf("after decode, len %d\n", total);
	for (i = 0; i < total; i++) {
		printf("%02x ", d[i]);
		if (i % 16 == 15)
			printf("\n");
	}

	return 0;
}
